package com.situ.crm.common.util;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import com.situ.crm.common.Constants;
import com.situ.crm.entity.User;

//操作请求session的工具类
public class SessionUtil {

	// 获取当前的Session
	public static HttpSession getSession() {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
		return request.getSession();
	}

	// 获取session中的Locale语言
	public static String getSessionLanguage() {
		Object obj = getSession().getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
		if (obj != null) {
			Locale locale = (Locale) obj;
			return locale.getLanguage();
		}
		return null;

	}

	public static User getCurrentUser() {
		Object obj = getSession().getAttribute(Constants.SESSION_CURRENT_KEY);
		if (obj != null) {
			return (User) obj;
		}
		return null;
	}

}
